<template>
  <div class="container">
    <div class="header">
      <h1 class="title">王者荣耀</h1>
    </div>

    <div class="filter">
      <span class="active">推荐</span>
      <span>不限性别</span>
    </div>

    <div class="player-list">
      <div class="player-card" v-for="p in player" :key="player.id">
        <img class="player-photo" :src="p.photo" alt="玩家头像" />
        <div class="player-info">
          <h2>{{ p.name }}</h2>
          <p>{{ p.description }}</p>
          <div class="player-details">
            <span class="player-score">{{ p.score }}</span>
            <span class="player-status">{{ p.status }}</span>
          </div>
        </div>
        <button class="invite-button" @click="invitePlayer(p.gid)">找他陪玩</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      player: {},
    };
  },
  mounted() {
    this.servePlayer();
  },
  methods: {
    servePlayer() {
      axios.post('http://localhost:8083/play/list', this.player).then(response => {
        this.player = response.data.data;
        console.log(this.player)
      }).catch(error => {
        console.error('Error fetching player:', error);
        this.error = error;
      })
    },
    invitePlayer(gid) {
      // 跳转到 accompany 页面，传递玩家信息
      this.$router.push({path: '/accompany', query: { gid :JSON.stringify(gid)}});
    },
  },
};
</script>

<style scoped>
.container {
  padding: 20px;
  background-color: #f7f9fc;
  height: 100vh;
  overflow-y: auto;
}

.header {
  text-align: center;
}

.title {
  font-size: 1.5em; /* 将标题字体设置为小一点 */
  font-weight: bold;
}

.filter {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.filter span {
  margin: 0 15px;
  cursor: pointer;
}

.filter .active {
  color: #007aff;
  font-weight: bold;
}

.player-list {
  margin-top: 20px;
}

.player-card {
  display: flex;
  align-items: center;
  background: white;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.player-photo {
  width: 70px;
  height: 70px;
  border-radius: 35px;
  margin-right: 15px;
}

.player-info {
  flex-grow: 1;
}

.player-details {
  display: flex;
  justify-content: space-between;
}

.player-score {
  font-weight: bold;
  color: #ffcc00;
}

.player-status {
  color: #666;
}

.invite-button {
  background-color: #00aaff;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 10px 15px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.invite-button:hover {
  background-color: #0088cc; /* Hover效果 */
}
</style>
